import Toast from '@vant/weapp/toast/toast';
import Notify from '@vant/weapp/notify/notify';
import { request } from '../../assets/js/request.js';
Page({
  formSubmit:function(e){
    if (e.detail.value.classId == null || e.detail.value.className == null || e.detail.value.classTime == null || e.detail.value.classPlace == null){
      Toast.fail({
        message: '信息不完整',
        mask: true,
        duration: 1000
      });
    }else{
      wx.showLoading({
        title: '加载中',
        mask: true
      })
      let thisData = {
        uid: this.data.uid,
        classId: e.detail.value.classId,
        className: e.detail.value.className,
        classTime: e.detail.value.classTime,
        classPlace: e.detail.value.classPlace,
      }
      request('/addClass.php',thisData).then((res=>{
        if (res.data == 'ok') {
          Toast.success({
            message: '添加成功',
            mask: true,
            duration: 1000
          });
        }else if(res.data == 'exist'){
          Toast({
            type:'fail',
            message: '课程ID冲突',
            mask: true,
            duration: 1000
          });
        }else if(res.data == 'fail'){
          Toast({
            type:'fail',
            message: '添加失败',
            mask: true,
            duration: 1000
          })
        }
      }))
      .catch((err)=>{
        Notify({ type: 'danger', message: '服务器繁忙，请稍后再试' });
      })
    }
  },
  
  data: {
    status:'',
    uid:""
  },

  onShow: function () {
    this.setData({
      uid: wx.getStorageSync('uid')
    })
  },

})